/**
 * 
 */
package com.wolfpire.proms.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.SQLQuery;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.wolfpire.proms.dao.FeedBackAuditDao;
import com.wolfpire.proms.model.FeedBackAudit;
import com.wolfpire.system.common.base.dao.impl.BaseHibernateDao;

/**
 * @author lihd
 *
 */

@Repository("feedBackAuditDao")
public class FeedBackAuditDaoImpl extends BaseHibernateDao<FeedBackAudit, Long>
		implements FeedBackAuditDao {

	@Override
	public int countAudit(Long feedBackId) {
		return this.findIntByCriteria(Restrictions.eq("feedbackId", feedBackId));
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	@Override
	public FeedBackAudit findLast(Long feedbackId) {
		String querySql = "SELECT * FROM t_feedback_audit fa WHERE fa.feedback_id=:feedbackId ORDER BY fa.create_time DESC LIMIT 1";
		List<String> propertyNames = new ArrayList<String>();
		propertyNames.add("feedbackId");
		List propertyValues = new ArrayList();
		propertyValues.add(feedbackId);
		SQLQuery query = this.createSqlQuery(querySql, propertyNames, propertyValues);
		query.addEntity(FeedBackAudit.class);
		return (FeedBackAudit) query.uniqueResult();
	}

}
